// Package main 提供Linux服务管理的公共功能
package go_service

import (
	"errors"
	"fmt"
)

// 定义特定的错误类型
var (
	ErrServiceNotFound    = errors.New("service not found")
	ErrServiceAlreadyRunning = errors.New("service is already running")
	ErrServiceNotRunning  = errors.New("service is not running")
	ErrStartFailed        = errors.New("failed to start service")
	ErrStopFailed         = errors.New("failed to stop service")
	ErrRestartFailed      = errors.New("failed to restart service")
	ErrStatusFailed       = errors.New("failed to get service status")
)

// ServiceError 表示服务操作相关的错误
type ServiceError struct {
	ServiceName string
	Operation   string
	Err         error
}

// Error 实现 error 接口
func (e *ServiceError) Error() string {
	return fmt.Sprintf("service %s: %s: %v", e.ServiceName, e.Operation, e.Err)
}

// Unwrap 实现 errors.Unwrapper 接口
func (e *ServiceError) Unwrap() error {
	return e.Err
}

// Is 实现 errors.Is 接口的支持
func (e *ServiceError) Is(target error) bool {
	return errors.Is(e.Err, target)
}